<!DOCTYPE html>
<html>
<head>
    <title>欢迎页面</title>
    <style>
        .welcome-container {
            width: 80%;
            margin: 50px auto;
            text-align: center;
            padding: 20px;
        }
        .welcome-message {
            font-size: 24px;
            color: #4CAF50;
            margin-bottom: 20px;
        }
        .logout-btn {
            padding: 10px 20px;
            background-color: #f44336;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .logout-btn:hover {
            background-color: #d32f2f;
        }
    </style>
</head>
<body>
    <div class="welcome-container">
        <h1 class="welcome-message">欢迎回来！</h1>
        <p id="username"></p>
        <button class="logout-btn" onclick="logout()">退出登录</button>
    </div>

    <script>
        // 检查登录状态
        const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}');
        if (!userInfo.username || !userInfo.token) {
            // 如果未登录，跳转回登录页
            window.location.href = '/index.html';
        } else {
            // 显示用户名
            document.getElementById('username').textContent = `欢迎回来，${userInfo.username}！`;
        }

        function logout() {
            // 清除登录信息
            localStorage.removeItem('userInfo');
            // 跳转回登录页
            window.location.href = '/index.html';
        }
    </script>
</body>
</html> 